﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MVC.Extensions;
using MVC.Models;
using Telerik.Web.Mvc;

namespace MVC.Controllers
{
	public partial class SetupController : Controller
	{
	
        public ActionResult ENT_ATT_LST()
        {
			var entities = new Entities();
			var items = entities.ENT_ATT;
            return View(items);
        }

		[AcceptVerbs(HttpVerbs.Post)]
        public ActionResult ENT_ATT_SAV(string id)
        {
			var entities = new Entities();
			var x_guid = new Guid(id);
			var item = entities.ENT_ATT.Where(x => x.Guid == x_guid).Single();
            if (TryUpdateModel(item))
            {
				entities.ENT_ATT.Attach(item);
				entities.Entry(item).State = System.Data.EntityState.Modified;
				entities.SaveChanges();
            }
            var items = entities.ENT_ATT;
            return RedirectToAction("ENT_ATT_LST");
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult ENT_ATT_INS()
        {
			var entities = new Entities();
			var item = new ENT_ATT();
            if (TryUpdateModel(item))
            {
				item.Guid = Guid.NewGuid();
				entities.ENT_ATT.Attach(item);
				entities.Entry(item).State = System.Data.EntityState.Added;
				entities.SaveChanges();
            }
            var items = entities.ENT_ATT;
            return RedirectToAction("ENT_ATT_LST");
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult ENT_ATT_DEL(string id)
        {
            var entities = new Entities();
			var x_guid = new Guid(id);
			var item = entities.ENT_ATT.Where(x => x.Guid == x_guid).Single();
			entities.Entry(item).State = System.Data.EntityState.Deleted;
			entities.SaveChanges();
			var items = entities.ENT_ATT;
            return RedirectToAction("ENT_ATT_LST");
        }
		/*
		[HttpGet]
		public ActionResult ENT_ATT_LST()
		{
			var entities = new Entities();
			var items = entities.ENT_ATT.OrderBy(x => x.Nome);
			return View(items);
		}

		[HttpGet]
		public ActionResult ENT_ATT_EDT(string param1, string param2)
		{
			ViewBag.Operation = param1;
			if(param1 == "CRT")
			{
				var item = new ENT_ATT();
				item.Guid = Guid.Empty;
				return View(item);
			}
			else if(param1 == "EDT")
			{
				var entities = new Entities();
				var x_guid = new Guid(param2);
				var item = entities.ENT_ATT.Where(x => x.Guid == x_guid).Single();
				return View(item);
			}
			else if(param1 == "DLT")
			{
				var entities = new Entities();
				var x_guid = new Guid(param2);
				var item = entities.ENT_ATT.Where(x => x.Guid == x_guid).Single();
				entities.ENT_ATT.Attach(item);
				entities.Entry(item).State = System.Data.EntityState.Deleted;
				entities.SaveChanges();
				return RedirectToAction("ENT_ATT_LST");
			}
			return RedirectToAction("ENT_ATT_LST");
		}

		[HttpPost]
		public ActionResult ENT_ATT_EDT(ENT_ATT item)
		{
			if (ModelState.IsValid == false)
            {
                return View(item);
            }
			if(item.Guid == Guid.Empty)
			{
				item.Guid = Guid.NewGuid();
				var entities = new Entities();
				entities.ENT_ATT.Attach(item);
				entities.Entry(item).State = System.Data.EntityState.Added;
				entities.SaveChanges();
				return RedirectToAction("ENT_ATT_LST");
			}
			else
			{
				var entities = new Entities();
				entities.ENT_ATT.Attach(item);
				entities.Entry(item).State = System.Data.EntityState.Modified;
				entities.SaveChanges();
				return RedirectToAction("ENT_ATT_EDT");
			}
		}
		*/
	
        public ActionResult CAM_LST()
        {
			var entities = new Entities();
			var items = entities.ENT_CAM;
            return View(items);
        }

		[AcceptVerbs(HttpVerbs.Post)]
        public ActionResult CAM_SAV(string id)
        {
			var entities = new Entities();
			var x_guid = new Guid(id);
			var item = entities.ENT_CAM.Where(x => x.Guid == x_guid).Single();
            if (TryUpdateModel(item))
            {
				entities.ENT_CAM.Attach(item);
				entities.Entry(item).State = System.Data.EntityState.Modified;
				entities.SaveChanges();
            }
            var items = entities.ENT_CAM;
            return RedirectToAction("CAM_LST");
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult CAM_INS()
        {
			var entities = new Entities();
			var item = new ENT_CAM();
            if (TryUpdateModel(item))
            {
				item.Guid = Guid.NewGuid();
				entities.ENT_CAM.Attach(item);
				entities.Entry(item).State = System.Data.EntityState.Added;
				entities.SaveChanges();
            }
            var items = entities.ENT_CAM;
            return RedirectToAction("CAM_LST");
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult CAM_DEL(string id)
        {
            var entities = new Entities();
			var x_guid = new Guid(id);
			var item = entities.ENT_CAM.Where(x => x.Guid == x_guid).Single();
			entities.Entry(item).State = System.Data.EntityState.Deleted;
			entities.SaveChanges();
			var items = entities.ENT_CAM;
            return RedirectToAction("CAM_LST");
        }
		/*
		[HttpGet]
		public ActionResult CAM_LST()
		{
			var entities = new Entities();
			var items = entities.ENT_CAM.OrderBy(x => x.Nome);
			return View(items);
		}

		[HttpGet]
		public ActionResult CAM_EDT(string param1, string param2)
		{
			ViewBag.Operation = param1;
			if(param1 == "CRT")
			{
				var item = new ENT_CAM();
				item.Guid = Guid.Empty;
				return View(item);
			}
			else if(param1 == "EDT")
			{
				var entities = new Entities();
				var x_guid = new Guid(param2);
				var item = entities.ENT_CAM.Where(x => x.Guid == x_guid).Single();
				return View(item);
			}
			else if(param1 == "DLT")
			{
				var entities = new Entities();
				var x_guid = new Guid(param2);
				var item = entities.ENT_CAM.Where(x => x.Guid == x_guid).Single();
				entities.ENT_CAM.Attach(item);
				entities.Entry(item).State = System.Data.EntityState.Deleted;
				entities.SaveChanges();
				return RedirectToAction("CAM_LST");
			}
			return RedirectToAction("CAM_LST");
		}

		[HttpPost]
		public ActionResult CAM_EDT(ENT_CAM item)
		{
			if (ModelState.IsValid == false)
            {
                return View(item);
            }
			if(item.Guid == Guid.Empty)
			{
				item.Guid = Guid.NewGuid();
				var entities = new Entities();
				entities.ENT_CAM.Attach(item);
				entities.Entry(item).State = System.Data.EntityState.Added;
				entities.SaveChanges();
				return RedirectToAction("CAM_LST");
			}
			else
			{
				var entities = new Entities();
				entities.ENT_CAM.Attach(item);
				entities.Entry(item).State = System.Data.EntityState.Modified;
				entities.SaveChanges();
				return RedirectToAction("CAM_EDT");
			}
		}
		*/
	
        public ActionResult CEN_LST()
        {
			var entities = new Entities();
			var items = entities.ENT_CEN;
            return View(items);
        }

		[AcceptVerbs(HttpVerbs.Post)]
        public ActionResult CEN_SAV(string id)
        {
			var entities = new Entities();
			var x_guid = new Guid(id);
			var item = entities.ENT_CEN.Where(x => x.Guid == x_guid).Single();
            if (TryUpdateModel(item))
            {
				entities.ENT_CEN.Attach(item);
				entities.Entry(item).State = System.Data.EntityState.Modified;
				entities.SaveChanges();
            }
            var items = entities.ENT_CEN;
            return RedirectToAction("CEN_LST");
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult CEN_INS()
        {
			var entities = new Entities();
			var item = new ENT_CEN();
            if (TryUpdateModel(item))
            {
				item.Guid = Guid.NewGuid();
				entities.ENT_CEN.Attach(item);
				entities.Entry(item).State = System.Data.EntityState.Added;
				entities.SaveChanges();
            }
            var items = entities.ENT_CEN;
            return RedirectToAction("CEN_LST");
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult CEN_DEL(string id)
        {
            var entities = new Entities();
			var x_guid = new Guid(id);
			var item = entities.ENT_CEN.Where(x => x.Guid == x_guid).Single();
			entities.Entry(item).State = System.Data.EntityState.Deleted;
			entities.SaveChanges();
			var items = entities.ENT_CEN;
            return RedirectToAction("CEN_LST");
        }
		/*
		[HttpGet]
		public ActionResult CEN_LST()
		{
			var entities = new Entities();
			var items = entities.ENT_CEN.OrderBy(x => x.Nome);
			return View(items);
		}

		[HttpGet]
		public ActionResult CEN_EDT(string param1, string param2)
		{
			ViewBag.Operation = param1;
			if(param1 == "CRT")
			{
				var item = new ENT_CEN();
				item.Guid = Guid.Empty;
				return View(item);
			}
			else if(param1 == "EDT")
			{
				var entities = new Entities();
				var x_guid = new Guid(param2);
				var item = entities.ENT_CEN.Where(x => x.Guid == x_guid).Single();
				return View(item);
			}
			else if(param1 == "DLT")
			{
				var entities = new Entities();
				var x_guid = new Guid(param2);
				var item = entities.ENT_CEN.Where(x => x.Guid == x_guid).Single();
				entities.ENT_CEN.Attach(item);
				entities.Entry(item).State = System.Data.EntityState.Deleted;
				entities.SaveChanges();
				return RedirectToAction("CEN_LST");
			}
			return RedirectToAction("CEN_LST");
		}

		[HttpPost]
		public ActionResult CEN_EDT(ENT_CEN item)
		{
			if (ModelState.IsValid == false)
            {
                return View(item);
            }
			if(item.Guid == Guid.Empty)
			{
				item.Guid = Guid.NewGuid();
				var entities = new Entities();
				entities.ENT_CEN.Attach(item);
				entities.Entry(item).State = System.Data.EntityState.Added;
				entities.SaveChanges();
				return RedirectToAction("CEN_LST");
			}
			else
			{
				var entities = new Entities();
				entities.ENT_CEN.Attach(item);
				entities.Entry(item).State = System.Data.EntityState.Modified;
				entities.SaveChanges();
				return RedirectToAction("CEN_EDT");
			}
		}
		*/
	
        public ActionResult ING_LST()
        {
			var entities = new Entities();
			var items = entities.ENT_ING;
            return View(items);
        }

		[AcceptVerbs(HttpVerbs.Post)]
        public ActionResult ING_SAV(string id)
        {
			var entities = new Entities();
			var x_guid = new Guid(id);
			var item = entities.ENT_ING.Where(x => x.Guid == x_guid).Single();
            if (TryUpdateModel(item))
            {
				entities.ENT_ING.Attach(item);
				entities.Entry(item).State = System.Data.EntityState.Modified;
				entities.SaveChanges();
            }
            var items = entities.ENT_ING;
            return RedirectToAction("ING_LST");
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult ING_INS()
        {
			var entities = new Entities();
			var item = new ENT_ING();
            if (TryUpdateModel(item))
            {
				item.Guid = Guid.NewGuid();
				entities.ENT_ING.Attach(item);
				entities.Entry(item).State = System.Data.EntityState.Added;
				entities.SaveChanges();
            }
            var items = entities.ENT_ING;
            return RedirectToAction("ING_LST");
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult ING_DEL(string id)
        {
            var entities = new Entities();
			var x_guid = new Guid(id);
			var item = entities.ENT_ING.Where(x => x.Guid == x_guid).Single();
			entities.Entry(item).State = System.Data.EntityState.Deleted;
			entities.SaveChanges();
			var items = entities.ENT_ING;
            return RedirectToAction("ING_LST");
        }
		/*
		[HttpGet]
		public ActionResult ING_LST()
		{
			var entities = new Entities();
			var items = entities.ENT_ING.OrderBy(x => x.Nome);
			return View(items);
		}

		[HttpGet]
		public ActionResult ING_EDT(string param1, string param2)
		{
			ViewBag.Operation = param1;
			if(param1 == "CRT")
			{
				var item = new ENT_ING();
				item.Guid = Guid.Empty;
				return View(item);
			}
			else if(param1 == "EDT")
			{
				var entities = new Entities();
				var x_guid = new Guid(param2);
				var item = entities.ENT_ING.Where(x => x.Guid == x_guid).Single();
				return View(item);
			}
			else if(param1 == "DLT")
			{
				var entities = new Entities();
				var x_guid = new Guid(param2);
				var item = entities.ENT_ING.Where(x => x.Guid == x_guid).Single();
				entities.ENT_ING.Attach(item);
				entities.Entry(item).State = System.Data.EntityState.Deleted;
				entities.SaveChanges();
				return RedirectToAction("ING_LST");
			}
			return RedirectToAction("ING_LST");
		}

		[HttpPost]
		public ActionResult ING_EDT(ENT_ING item)
		{
			if (ModelState.IsValid == false)
            {
                return View(item);
            }
			if(item.Guid == Guid.Empty)
			{
				item.Guid = Guid.NewGuid();
				var entities = new Entities();
				entities.ENT_ING.Attach(item);
				entities.Entry(item).State = System.Data.EntityState.Added;
				entities.SaveChanges();
				return RedirectToAction("ING_LST");
			}
			else
			{
				var entities = new Entities();
				entities.ENT_ING.Attach(item);
				entities.Entry(item).State = System.Data.EntityState.Modified;
				entities.SaveChanges();
				return RedirectToAction("ING_EDT");
			}
		}
		*/
	
        public ActionResult PIA_LST()
        {
			var entities = new Entities();
			var items = entities.ENT_PIA;
            return View(items);
        }

		[AcceptVerbs(HttpVerbs.Post)]
        public ActionResult PIA_SAV(string id)
        {
			var entities = new Entities();
			var x_guid = new Guid(id);
			var item = entities.ENT_PIA.Where(x => x.Guid == x_guid).Single();
            if (TryUpdateModel(item))
            {
				entities.ENT_PIA.Attach(item);
				entities.Entry(item).State = System.Data.EntityState.Modified;
				entities.SaveChanges();
            }
            var items = entities.ENT_PIA;
            return RedirectToAction("PIA_LST");
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult PIA_INS()
        {
			var entities = new Entities();
			var item = new ENT_PIA();
            if (TryUpdateModel(item))
            {
				item.Guid = Guid.NewGuid();
				entities.ENT_PIA.Attach(item);
				entities.Entry(item).State = System.Data.EntityState.Added;
				entities.SaveChanges();
            }
            var items = entities.ENT_PIA;
            return RedirectToAction("PIA_LST");
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult PIA_DEL(string id)
        {
            var entities = new Entities();
			var x_guid = new Guid(id);
			var item = entities.ENT_PIA.Where(x => x.Guid == x_guid).Single();
			entities.Entry(item).State = System.Data.EntityState.Deleted;
			entities.SaveChanges();
			var items = entities.ENT_PIA;
            return RedirectToAction("PIA_LST");
        }
		/*
		[HttpGet]
		public ActionResult PIA_LST()
		{
			var entities = new Entities();
			var items = entities.ENT_PIA.OrderBy(x => x.Nome);
			return View(items);
		}

		[HttpGet]
		public ActionResult PIA_EDT(string param1, string param2)
		{
			ViewBag.Operation = param1;
			if(param1 == "CRT")
			{
				var item = new ENT_PIA();
				item.Guid = Guid.Empty;
				return View(item);
			}
			else if(param1 == "EDT")
			{
				var entities = new Entities();
				var x_guid = new Guid(param2);
				var item = entities.ENT_PIA.Where(x => x.Guid == x_guid).Single();
				return View(item);
			}
			else if(param1 == "DLT")
			{
				var entities = new Entities();
				var x_guid = new Guid(param2);
				var item = entities.ENT_PIA.Where(x => x.Guid == x_guid).Single();
				entities.ENT_PIA.Attach(item);
				entities.Entry(item).State = System.Data.EntityState.Deleted;
				entities.SaveChanges();
				return RedirectToAction("PIA_LST");
			}
			return RedirectToAction("PIA_LST");
		}

		[HttpPost]
		public ActionResult PIA_EDT(ENT_PIA item)
		{
			if (ModelState.IsValid == false)
            {
                return View(item);
            }
			if(item.Guid == Guid.Empty)
			{
				item.Guid = Guid.NewGuid();
				var entities = new Entities();
				entities.ENT_PIA.Attach(item);
				entities.Entry(item).State = System.Data.EntityState.Added;
				entities.SaveChanges();
				return RedirectToAction("PIA_LST");
			}
			else
			{
				var entities = new Entities();
				entities.ENT_PIA.Attach(item);
				entities.Entry(item).State = System.Data.EntityState.Modified;
				entities.SaveChanges();
				return RedirectToAction("PIA_EDT");
			}
		}
		*/
	
        public ActionResult STA_LST()
        {
			var entities = new Entities();
			var items = entities.ENT_STA;
            return View(items);
        }

		[AcceptVerbs(HttpVerbs.Post)]
        public ActionResult STA_SAV(string id)
        {
			var entities = new Entities();
			var x_guid = new Guid(id);
			var item = entities.ENT_STA.Where(x => x.Guid == x_guid).Single();
            if (TryUpdateModel(item))
            {
				entities.ENT_STA.Attach(item);
				entities.Entry(item).State = System.Data.EntityState.Modified;
				entities.SaveChanges();
            }
            var items = entities.ENT_STA;
            return RedirectToAction("STA_LST");
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult STA_INS()
        {
			var entities = new Entities();
			var item = new ENT_STA();
            if (TryUpdateModel(item))
            {
				item.Guid = Guid.NewGuid();
				entities.ENT_STA.Attach(item);
				entities.Entry(item).State = System.Data.EntityState.Added;
				entities.SaveChanges();
            }
            var items = entities.ENT_STA;
            return RedirectToAction("STA_LST");
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult STA_DEL(string id)
        {
            var entities = new Entities();
			var x_guid = new Guid(id);
			var item = entities.ENT_STA.Where(x => x.Guid == x_guid).Single();
			entities.Entry(item).State = System.Data.EntityState.Deleted;
			entities.SaveChanges();
			var items = entities.ENT_STA;
            return RedirectToAction("STA_LST");
        }
		/*
		[HttpGet]
		public ActionResult STA_LST()
		{
			var entities = new Entities();
			var items = entities.ENT_STA.OrderBy(x => x.Nome);
			return View(items);
		}

		[HttpGet]
		public ActionResult STA_EDT(string param1, string param2)
		{
			ViewBag.Operation = param1;
			if(param1 == "CRT")
			{
				var item = new ENT_STA();
				item.Guid = Guid.Empty;
				return View(item);
			}
			else if(param1 == "EDT")
			{
				var entities = new Entities();
				var x_guid = new Guid(param2);
				var item = entities.ENT_STA.Where(x => x.Guid == x_guid).Single();
				return View(item);
			}
			else if(param1 == "DLT")
			{
				var entities = new Entities();
				var x_guid = new Guid(param2);
				var item = entities.ENT_STA.Where(x => x.Guid == x_guid).Single();
				entities.ENT_STA.Attach(item);
				entities.Entry(item).State = System.Data.EntityState.Deleted;
				entities.SaveChanges();
				return RedirectToAction("STA_LST");
			}
			return RedirectToAction("STA_LST");
		}

		[HttpPost]
		public ActionResult STA_EDT(ENT_STA item)
		{
			if (ModelState.IsValid == false)
            {
                return View(item);
            }
			if(item.Guid == Guid.Empty)
			{
				item.Guid = Guid.NewGuid();
				var entities = new Entities();
				entities.ENT_STA.Attach(item);
				entities.Entry(item).State = System.Data.EntityState.Added;
				entities.SaveChanges();
				return RedirectToAction("STA_LST");
			}
			else
			{
				var entities = new Entities();
				entities.ENT_STA.Attach(item);
				entities.Entry(item).State = System.Data.EntityState.Modified;
				entities.SaveChanges();
				return RedirectToAction("STA_EDT");
			}
		}
		*/
		}
}
